package com.jxchexie.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jxchexie.model.User;
import com.jxchexie.signin.R;

import java.util.ArrayList;


/**
 * Created by zj
 */
public class UserAdminAdapter extends RecyclerView.Adapter<UserAdminAdapter.ListViewHolder> {


    private ArrayList<User> mdatas;

    private Context mContext;

    public UserAdminAdapter(ArrayList<User> datas, Context context) {
        mdatas = datas;
        mContext = context;
    }

    @Override
    public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ListViewHolder holder = new ListViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_admin_unsigned_users, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(ListViewHolder holder, int position) {
        holder.unsigned_admin_user.setText(mdatas.get(position).getUsername());
        holder.unsigned_admin_signed_count.setText(mdatas.get(position).getSigned_count()+"次已签到");
        holder.unsigned_admin_unsigned_count.setText(mdatas.get(position).getUnsigned_count()+"次未签到");
        holder.unsigned_admin_userdate.setText("最近一次签到日期:"+mdatas.get(position).getDate());
    }

    @Override
    public int getItemCount() {
        if(mdatas==null || mdatas.size()<=0){
            return 0;
        }
        return mdatas.size();
    }

    static class ListViewHolder extends RecyclerView.ViewHolder {

        TextView unsigned_admin_user;
        TextView unsigned_admin_signed_count;
        TextView unsigned_admin_unsigned_count;
        TextView unsigned_admin_userdate;

        public ListViewHolder(View itemView) {
            super(itemView);
            unsigned_admin_user=(TextView) itemView.findViewById(R.id.unsigned_admin_user);
            unsigned_admin_signed_count=(TextView) itemView.findViewById(R.id.unsigned_admin_signed_count);
            unsigned_admin_unsigned_count=(TextView) itemView.findViewById(R.id.unsigned_admin_unsigned_count);
            unsigned_admin_userdate=(TextView) itemView.findViewById(R.id.unsigned_admin_userdate);
        }
    }

}